import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 分类导航索引
    currentCat: 0,
    // 检测是否在登录状态
    isLogin: false,
    // 存储token
    token: window.localStorage.getItem('token') || false,
    // 存储登录用户的信息
    user: ''
  },
  mutations: {
    // 设置分类导航索引
    setCurrentCat: function(state, index) {
      state.currentCat = index;
    },
    // 设置登录状态
    setIsLogin: function(state, flag) {
      state.isLogin = flag;
    },
    // 设置token
    setToken: function(state, token) {
      state.token = token;
    },
    // 设置用户信息
    setUser: function(state, user) {
      state.user = user;
    },
    // 退出登录清除数据
    clearParams: function(state) {
      state.user = ''
      state.token = false
      state.isLogin = false
    }
  },
  actions: {
  },
  modules: {
  }
})
